<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Register</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
</head>
<body>
<form action="" method="post">
    {#必须加上csrf_toke才可以请求提交#}
    {#除非注释掉csrfmiddleware#}
    {% csrf_token %}
    用户名: <input type="text" alt="用户名" name="username"><br>
    密码 <input type="password" alt="密码" name="password"><br>
    <input type="button" id="submit">
</form>

<script>
    //获取到表单内的所有值
    //$("form").serialize();
    $('#submit').click(function () {
        username = $("[name='username']").val();
        password = $("[name='password']").val();
        csrf = $("[type='hidden']").val();
        $.post("/register/", {'username': username, 'password': password, 'csrfmiddlewaretoken': csrf},function (data) {
            console.log(data)
        })
    });
</script>
</body>
</html>